package cn.wizzer.app.web.modules.controllers.platform.user.view;

import cn.wizzer.app.crown.modules.models.enums.MatchTypeEnum;
import cn.wizzer.app.crown.modules.services.ViewPointService;
import cn.wizzer.app.user.modules.models.enums.ViewStatusEnum;
import cn.wizzer.app.web.commons.ulog.annotation.SLog;
import cn.wizzer.framework.base.Result;
import com.alibaba.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;


@IocBean
@At("/platform/user/view")
public class UserViewController {

    @Inject
    @Reference
    private ViewPointService viewPointService;

    @At("/")
    @Ok("beetl:/platform/user/view/index.html")
    @RequiresPermissions("user.view.list")
    public void index() {

    }


    /**
     * 观点列表查询
     *
     * @param searchKeyword
     * @param searchDate
     * @param matchType
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @At
    @Ok("json:full")
    @RequiresPermissions("user.view.list")
    public Object data(@Param("searchKeyword") String searchKeyword,
                       @Param("searchDate") String[] searchDate,
                       @Param("matchType") MatchTypeEnum matchType,
                       @Param("status") ViewStatusEnum status,
                       @Param("pageNumber") int pageNumber,
                       @Param("pageSize") int pageSize) {
        return Result.success().addData(viewPointService.listPage(pageNumber, pageSize, searchKeyword, searchDate, matchType, status));
    }

    /**
     * 删除观点
     *
     * @param id String
     * @return Object
     */
    @At("/del/?")
    @Ok("json")
    @RequiresPermissions("user.view.edit")
    @SLog(tag = "删除观点")
    public Object del(String id) {
        viewPointService.update(Chain.make("delFlag", 1), Cnd.where("id", "=", id));
        return Result.success();
    }

    /**
     * 观点审核
     *
     * @param id
     * @param status
     * @param remark
     * @return Object
     */
    @At
    @Ok("json")
    @RequiresPermissions("user.view.edit")
    @SLog(tag = "观点审核")
    public Object audit(String id, String status, String remark) {
        viewPointService.update(Chain.make("status", status).add("remark", remark), Cnd.where("id", "=", id));
        return Result.success();
    }

    /**
     * 获取赛事全部类型
     * @return
     */
    @At
    @Ok("json")
    public Object matchTypeList() {
        try {
            return Result.success().addData(MatchTypeEnum.toList());
        } catch (Exception e) {
            return Result.error();
        }
    }

    /**
     * 获取观点状态全部类型
     * @return
     */
    @At
    @Ok("json")
    public Object statusList() {
        try {
            return Result.success().addData(ViewStatusEnum.toList());
        } catch (Exception e) {
            return Result.error();
        }
    }

}
